#include <cstdio>
#include <cstring>

char str[ 10001 ];

int main( )
{
    int i, j, n, b, d, f, F, ans = 0x7fffffff, t;
    while ( scanf("%d%d%d%d%d", &n, &b, &d, &f, &F) != EOF )
    {
        ans = 0x7fffffff;
        while ( n-- )
        {
            scanf("%s", str);
            t = 0;
            for ( i = 0; i < strlen( str ); i++ )
                switch( str[ i ] )
                {
                    case 'A': t += b + d + f; break;
                    case 'B': t += b * 2 + d * 2 + F; break;
                    case 'C': t += b * 3 + d * 3 + F * 2; break;
                }
            if ( ans > t ) ans = t;
        }
        printf("%d\n", ans);
    }
    return 0;
}
